<?php
namespace jy_credit4shop;
defined('BY_JYA') or exit('error');
/*
	分红插件工具类
*/
class model extends \plugin{
	
	public function create_condition($conditions){
		if(!$conditions){
			return '';
		}
		if(!is_array($conditions)){
			$conditions=json_decode($conditions,true);
		}
		$level_up_types=$this->level_up_types;
		$current_level_up_types=$this->current_level_up_types();
		$str='';
		foreach($current_level_up_types as $key){
			$str.=$level_up_types[$key].'达'.$conditions[$key].';';
		}
		return $str;
	}
	public function create($logid=0){
		$isadd=pdo_get('core_credit_log',array('type'=>2,'is_add'=>1,'plugin'=>'jy_credit4shop','tag'=>$logid,'uniacid'=>$_SESSION['uniacid']));
		if($isadd['id']){
			exi('该兑换记录已经退过币了！','error');
		}else{
			$log=pdo_get('jy_creditshop_log',array('id'=>$logid,'uniacid'=>$_SESSION['uniacid']));
			$goods=pdo_get('jy_creditshop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$log['goodsid']));
			model('core/member')->member_credit($_SESSION['uid'],'credit2',$goods['price'],true,'jy_credit4shop','兑换商品退币到余额');
		}
		$update=array('status'=>3,'time_finish'=>time());
		pdo_update('jy_creditshop_log',$update,array('id'=>$logid,'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
}